/**
 * File Name	: TxAccountRowCallbackHandler.java
 * Author		: adelwin
 * Create Date	: 14-Apr-2011:PM 10:24:05
 *
 * Copyright (c) 2011 adelwin. All Rights Reserved. <BR>
 * <BR>
 * This software contains confidential and proprietary information of
 * Adelwin. ("Confidential Information").<BR>
 * <BR>
 * Such Confidential Information shall not be disclosed and it shall
 * only be used in accordance with the terms of the license agreement
 * entered into with Solveware Independent; other than in accordance with the written
 * permission of Solveware Independent. <BR>
 *
 */
package com.uobgroup.cmt.conversion.handler;

import java.sql.SQLException;

import org.apache.log4j.Logger;

import com.uobgroup.cmt.base.dao.IBaseSourceDao;
import com.uobgroup.cmt.base.dao.IBaseTargetDao;
import com.uobgroup.cmt.base.exception.BaseException;
import com.uobgroup.cmt.base.handler.BaseRowCallbackHandler;
import com.uobgroup.cmt.conversion.model.source.TclsSecCommitmentModel;
import com.uobgroup.cmt.conversion.model.target.SmlCollateralModel;

/**
 * @author adelwin
 *
 */
public class SmlCollateralCallbackHandler<M extends SmlCollateralModel> extends BaseRowCallbackHandler<M> {
	protected Logger logger = Logger.getLogger(SmlCollateralCallbackHandler.class);
	
	private IBaseSourceDao<TclsSecCommitmentModel> sourcePlsSecCommitmentDao;
	private IBaseTargetDao<SmlCollateralModel> targetSmlCollateralDao;

	public IBaseSourceDao<TclsSecCommitmentModel> getSourcePlsSecCommitmentDao() {
		return sourcePlsSecCommitmentDao;
	}

	public void setSourcePlsSecCommitmentDao(IBaseSourceDao<TclsSecCommitmentModel> sourcePlsSecCommitmentDao) {
		this.sourcePlsSecCommitmentDao = sourcePlsSecCommitmentDao;
	}

	public IBaseTargetDao<SmlCollateralModel> getTargetSmlCollateralDao() {
		return targetSmlCollateralDao;
	}

	public void setTargetSmlCollateralDao(IBaseTargetDao<SmlCollateralModel> targetSmlCollateralDao) {
		this.targetSmlCollateralDao = targetSmlCollateralDao;
	}

	@Override
	public void processRow(M rowItem) throws SQLException, BaseException {
		//get latest valuation details
		TclsSecCommitmentModel secCommitmentModel = new TclsSecCommitmentModel();
		secCommitmentModel.setSecSeqNo(rowItem.getSecSeqNo());
		secCommitmentModel = this.sourcePlsSecCommitmentDao.getListByCriteria(secCommitmentModel).get(0);
		
		rowItem.setCollId(secCommitmentModel.getSecSeqNo());
		rowItem.setLatestValAmt(secCommitmentModel.getValuationAmt());
		rowItem.setLatestValCcy(secCommitmentModel.getValuationCcy());
		
		targetSmlCollateralDao.insert(rowItem);
	}


}
